<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div>
        <button class="reduce">-</button>
        <button class="num">0</button>
        <button class="increase">+</button>
    </div>
    <div>
        <button class="reduce">-</button>
        <button class="num">0</button>
        <button class="increase">+</button>
    </div> 
     <div>
        <button class="reduce">-</button>
        <button class="num">0</button>
        <button class="increase">+</button>
    </div>
    <div>
        <button class="reduce">-</button>
        <button class="num">0</button>
        <button class="increase">+</button>
    </div>
    <div>
        <button class="reduce">-</button>
        <button class="num">0</button>
        <button class="increase">+</button>
    </div>
</body>
<script>
   var reduce=document.getElementsByClassName("reduce");
   var num=document.getElementsByClassName("num");
   var increase=document.getElementsByClassName("increase");
   function f(i){
        var count=0;
        reduce[i].onclick=function(){
            num[i].innerHTML=--count;
        }
        increase[i].onclick=function(){//闭包
            num[i].innerHTML=++count;
        }
   }
    for(var i=0;i<reduce.length;i++){
        f(i);   
    }
</script>
</html>